package fun.liuyu2783.dtc.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import fun.liuyu2783.dtc.common.Response;
import fun.liuyu2783.dtc.goods.dao.GoodsMapper;
import fun.liuyu2783.dtc.goods.dto.Goods;
import fun.liuyu2783.dtc.goods.service.GoodsService;
import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liuyu2783
 * @since 2021-11-23
 */
@Slf4j
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Response stock(String tradeId, int saleCount) {
        log.info("xid={}", RootContext.getXID());
        Goods goods = new Goods();
        goods.setId("1");
        goods.setGoodsName("111");
        goods.setTradeId(tradeId);
        super.save(goods);
        return Response.success();
    }

    @Override
    public Response page() {
        QueryWrapper queryWrapper = new QueryWrapper();
        int pageSize = 10;
        int pageNum = 1;
        Page page = new Page(pageNum, pageSize);
        IPage data = super.page(page, queryWrapper);
        return Response.success(data);
    }
}
